package g

import (
	"fmt"
	"gf-app/frame/gins"
	gin "github.com/gin-gonic/gin"
	"github.com/gogf/gf/database/gdb"
	gf "github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/os/gcfg"
)

var (
	ginsServer *gins.Server
)

// Server returns an instance of http server with specified name.
func Server() *gins.Server {
	if ginsServer != nil {
		fmt.Println("-------- ginServer 已经初始化，返回已经有的实例")
		return ginsServer
	} else {
		fmt.Println("-------- ginServer 创建新实例")
		ginsServer = gins.New()
		return ginsServer
	}
}

// Cfg is alias of Config.
// See Config.
func Cfg(name ...string) *gcfg.Config {
	return gf.Config(name...)
}

// DB is alias of Database.
// See Database.
func DB(name ...string) gdb.DB {
	return gf.Database(name...)
}

// 返回gin的Default方法，方便go-micro集成
func GinEngine() *gin.Engine {
	fmt.Printf("------ GinEngine() \n")
	return Server().GetGinEngine()
}
